<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%links}}".
 *
 * @property string $id
 * @property string $name
 * @property string $url
 * @property string $image
 * @property string $sort
 * @property string $create_time
 */
class Links extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%links}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'url'], 'required'],
            [['sort', 'create_time'], 'integer'],
            [['name'], 'string', 'max' => 40],
            [['url'], 'string', 'max' => 100],
			[['sort'], 'filter', 'filter'=> function ($val) {
				return $val ? abs(intval($val)) : 10;
			}],
			[['create_time'], 'default', 'value' => function () {
				return time();
			}],
            [['image'], 'file', 'extensions' => 'jpg, png, gif, jpeg', 'mimeTypes' => 'image/jpg, image/png, image/gif, image/jpeg']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '链接名称',
            'url' => '链接地址',
            'image' => 'logo路径',
            'sort' => '排序',
            'create_time' => '创建时间',
        ];
    }
}
